#include <g3.h>


rainbowfont(str, row, col)
char *str;
int row, col;
{

	int idx, color = 7;
	char foo[2];

	foo[1]=0;

	for (idx=0;str[idx]!=0;idx++) {
	     foo[0] = str[idx];
	     if (foo[0] == 'l' || foo[0] == 'i' || foo[0] ==32)col -=1;
	     lofont(foo,row,col,color,-1,1);
	     color++;
	     if (color > 15)color = 7;
	     if (foo[0] == 'l' || foo[0] == 'i' || foo[0] ==32)col+=5;
	     else col+=6;
	}


}

loboxes()
{
	int x1,y1,x2,y2, color;


    loclear();

	lobox(0,0,39,47,3);
	rainbowfont("Lores",0,0);
	rainbowfont("Graphic",8,0);
	rainbowfont("Demo in",16,0);
	rainbowfont("Aztec C",24,0);
	rainbowfont("by Bill",32,0);
	rainbowfont("Buckels",40,0);


 	for (;;) {
	   if (kbhit() > 0) {
		  clearkey();
		  break;
	   }
	}
	loclear();


	x1 = 0;
	x2 = 39;
	y1 = 0;
	y2 = 47;

	for (color = 1; color < 16; color++) {
        lobox(x1,y1,x2,y2, color);
        y1++;
        y2--;
        x1++;
        x2--;

    }

	for (;;) {
	   if (kbhit() > 0) {
		  clearkey();
		  break;
	   }
	}
	loclear();
}



rod ()
{

    int i, j, k, w, fmi, fmk, color, c=0;

	for (w = 3; w < 51; w++) {
		for (i = 1; i < 20; i++) {
			for (j = 0; j < 20; j++) {
				k = i + j;
				color = (j * 3) / (i + 3) + i * w / 12;
				fmi = 40 - i;
				fmk = 40 - k;

				setcolor(color);

				loplot( i, k);
				loplot( k, i);

				loplot( fmi, fmk);
				loplot( fmk, fmi);

				loplot( k, fmi);
				loplot( fmi, k);

				loplot( i, fmk);
				loplot( fmk, i);
				if ((c = kbhit()) > 0) {
					clearkey();
					return c-128;

				}
			}
		}
	}

	if ((c = kbhit()) > 0) {
		clearkey();
		c-=128;
	}
	return c;

}





main()
{


    setcrtmode(LORES);
    clearkey();
    loboxes();
    for (;;) {
        loclear();
		if (rod()==27)break;

    }
    loclear();
	setcrtmode(TEXTMODE);
	scr_apple();
	reboot();

}



